package org.footito.android.tools;

import org.footito.android.R;
import org.footito.android.activity.Timeline;
import org.footito.android.data.TeamStatus;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

public class NotificationHelper {
	private static final String PACKAGENAME = "org.footito.android";
	private static final int NOTIF_PIC = R.drawable.ic_stat_notif;
	private static String MESSAGE_LASTASTUS;
	private static String MESSAGE_NEWSTATUS;
	private Context context;
	private NotificationManager notificationManager;

	public NotificationHelper(Context context) {
		this.context = context;
		MESSAGE_NEWSTATUS = context.getResources().getString(R.string.new_status);
		MESSAGE_LASTASTUS = context.getResources().getString(R.string.last_status);
		notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
	}

	public void notifyNewStatus(TeamStatus status) {
		Notification notification = new Notification(NOTIF_PIC, MESSAGE_NEWSTATUS, System.currentTimeMillis());

		String message = status.getTeam().getName() + ": " + status.getContent();

		notification.flags |= Notification.FLAG_AUTO_CANCEL;
		notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
		Intent intent = new Intent(context, Timeline.class);
		PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent, 0);

		notification.setLatestEventInfo(context, MESSAGE_LASTASTUS, message, pIntent);

		notificationManager.notify(0, notification);
	}

	public void clearNotifications() {
		notificationManager.cancel(0);
	}
}
